<?php

namespace app\admin\model;

use think\Model;
use think\Session;

class Store  extends Model
{
    /**
     * @var array|bool|float|int|mixed|object|\stdClass|null
     */
    protected $name = 'store';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';
    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (empty($row['service_secret'])) {
                $pk = $row->getPk();
                $secret = Session::get('admin')['secret'];
                $row->getQuery()->where($pk, $row[$pk])->update(['service_secret' =>$secret]);
            }
        });
    }

}